package com.sam.ble.unimplements;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;

public class BLEBRHelper {
    private static BLEBRHelper self;
    public synchronized static BLEBRHelper getInstance(){
        if(self == null) self = new BLEBRHelper();
        return self;
    }

    //==============================================================================================
    //                         重新登录的广播
    //==============================================================================================
    private static final String RELOGIN_BROADCAST_RECEIVER = "COM.SAM.RELOGIN.ACTION";
    public  void registerReloginBR(Context context){
        ReloginBR receiver = new ReloginBR();
        IntentFilter filter = new IntentFilter();
        filter.addAction(RELOGIN_BROADCAST_RECEIVER);
        context.registerReceiver(receiver, filter);
    }
    public void sendReloginBR(Context context){
        Intent intent = new Intent(RELOGIN_BROADCAST_RECEIVER);
        context.sendBroadcast(intent);
    }

    ReloginCallback reloginCallback;
    public void setReloginCallback(ReloginCallback reloginCallback){
        this.reloginCallback = reloginCallback;
    }

    class ReloginBR extends BroadcastReceiver{

        @Override
        public void onReceive(Context context, Intent intent) {
            if(intent.getAction().equals(RELOGIN_BROADCAST_RECEIVER)){
                if(reloginCallback != null)reloginCallback.relogin();
            }
        }
    }

    public interface ReloginCallback{
        void relogin();
    }
    //==============================================================================================
    //                         找医生咨询的广播
    //==============================================================================================
    private static final String SEEK_MEDICAL_ADVICE_BROADCAST_RECEIVER = "COM.SAM.SEEK.MEDICAL.ADVICE.ACTION";
    public  void registerSeekAdviceBR(Context context){
        SeekAdviceBR receiver = new SeekAdviceBR();
        IntentFilter filter = new IntentFilter();
        filter.addAction(SEEK_MEDICAL_ADVICE_BROADCAST_RECEIVER);
        context.registerReceiver(receiver, filter);
    }
    public void sendSeekAdviceBR(Context context){
        Intent intent = new Intent(SEEK_MEDICAL_ADVICE_BROADCAST_RECEIVER);
        context.sendBroadcast(intent);
    }

    SeekAdviceCallback seekAdviceCallback;
    public void setSeekAdviceCallback(SeekAdviceCallback seekAdviceCallback){
        this.seekAdviceCallback = seekAdviceCallback;
    }

    class SeekAdviceBR extends BroadcastReceiver{

        @Override
        public void onReceive(Context context, Intent intent) {
            if(intent.getAction().equals(SEEK_MEDICAL_ADVICE_BROADCAST_RECEIVER)){
                if(seekAdviceCallback != null)seekAdviceCallback.seekMedicalAdvice();
            }
        }
    }

    public interface SeekAdviceCallback{
        void seekMedicalAdvice();
    }

}
